package com.lobo.blog.interceptor;

import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @authoer:MacieSerenity
 * @createDate: 2022/9/23
 * @description:
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    /**
     * 添加web资源的拦截器
     * addPathPatterns：该方法用于指定拦截路径，例如拦截路径为“/**”，表示拦截所有请求，包括对静态资源的请求。
     * excludePathPatterns：该方法用于排除拦截路径，即指定不需要被拦截器拦截的请求。
     *
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(
                        new StaticResourceInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/*", "./lib/**", "./images/**", "./css/**", "./js/**");
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/admin/**")
                .excludePathPatterns("/admin/login", "./lib/**", "./images/**", "./css/**", "./js/**");
    }
}
